package com.dyp.demo.indicator;

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;

/**
 * 数据汇总到http://localhost:8080/actuator/health中的my里面，因为会去掉类名中的HealthIndicator，如果找不到就用类名全称
 * {
 *     "status":"UP",
 *     "components":{
 *         "diskSpace":{
 *             "status":"UP",
 *             "details":{
 *                 "total":965974630400,
 *                 "free":709547364352,
 *                 "threshold":10485760,
 *                 "exists":true
 *             }
 *         },
 *         "my":{
 *             "status":"UP"
 *         },
 *         "ping":{
 *             "status":"UP"
 *         }
 *     }
 * }
 */
@Component
public class MyHealthIndicator implements HealthIndicator {
    private int check(){
        System.out.println("check what you want");
        return 0;
    }

    @Override
    public Health health() {
        int errorCode = check(); // perform some specific health check
        if (errorCode != 0) {
            return Health.down().withDetail("Error Code", errorCode).build();
        }
        return Health.up().build();
    }
}
